﻿
using System;
using System.Text;
using __ts.Core.Configuration;
using __ts.Core.Plugin;
using __ts.Core.Utilities;

namespace server.test_3_0_0
{
    /// <summary>
    /// 服务实现类，用以实现服务契约
    /// </summary>
    public class Service : Contract
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string HelloWorld()
        {
            IPlugin p = Plugin.GetInstance;

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("插件名称：{0}<br/>\n", p.Name)
              .AppendFormat("插件描述：{0}<br/>\n", p.Description)
              .AppendFormat("插件Key：{0}<br/>\n", p.Key)
              .AppendFormat("监听的端口：{0}<br/>\n", string.Join(",", Array.ConvertAll<int, string>(p.Ports.ToArray(), Convert.ToString)))
              .AppendFormat("插件托管状态：{0}<br/>\n", p.State)
              .AppendFormat("插件文件路径：{0}<br/>\n", p.AssemblyPath)
              .Append("=============================<br/>\n")
              .AppendFormat("调用这个服务时用的端口：{0}<br/>\n", WcfHelper.GetViaPort)
              .AppendFormat("获取端口{0}对应的配置, 如：agentName = {1}<br/>\n",
                  WcfHelper.GetViaPort,
                  ConfigManager.AppSettings[WcfHelper.GetViaPort].Get("agentName"));

            return sb.ToString();
        }
    }
}
